package com.morehair.utils;

import com.morehair.bean.vo.admin.BaseRespVo;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import java.util.List;

public class ValidUtil {
    public static BaseRespVo valid(BindingResult bindingResult) {
        StringBuilder stringBuilder = new StringBuilder();
        List<FieldError> fieldErrors = bindingResult.getFieldErrors();
        for (FieldError fieldError : fieldErrors) {
            String field = fieldError.getField();
            Object rejectedValue = fieldError.getRejectedValue();
            String defaultMessage = fieldError.getDefaultMessage();
            String message = "请求参数" + field + "因为" + rejectedValue + "没有通过校验;" + defaultMessage;
            stringBuilder.append(message+";  ");
        }
        return BaseRespVo.fail(stringBuilder.toString());
    }
}
